// 设置

<template>
  <view class="set">
    <view class="avatar">
      <image :src="$filters.filterImg(userInfo.avatar)" />
      <text>{{ userInfo.nickname }}</text>
    </view>
    <view class="list">
      <view class="item" @tap="logout">退出登录</view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      userInfo: this.$store.state.userInfo
    }
  },
  methods: {
    // 退出登录
    logout() {
      uni.showModal({
        title: '提示',
        content: '是否确认退出登录？',
        success: async ({ confirm }) => {
          if (confirm) {
            const res = await this.$api.user.logout()
            if (res.code == 200) {
              uni.showToast({
                title: res.msg,
                icon: 'none',
                mask: true
              })
              uni.clearStorageSync()
              setTimeout(() => {
                uni.reLaunch({ url: '/pages/login/index' })
              }, 600)
            }
          }
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.avatar {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 438rpx;
  image {
    width: 160rpx;
    height: 160rpx;
    border-radius: 50%;
  }
  text {
    margin-top: 20rpx;
    font-size: 48rpx;
    font-weight: bold;
    color: #111111;
  }
}

.list {
  .item {
    width: 702rpx;
    height: 100rpx;
    margin: 0 auto;
    background: #ffffff;
    border-radius: 16rpx;
    text-align: center;
    line-height: 100rpx;
    color: #111111;
  }
}
</style>
